// b2c/index/index.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cookie:"",
    wh:null,
    docs:[],
    fid:"",
    docsPanren:[],
    https:"https://csb2c.fenxiangqu.cn/",
    imgerror:'app/images/nnnnnnn.png'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    })
    try {
      var res = wx.getSystemInfoSync();
      this.setData({
        wh: res.windowHeight + 'px'
      })

    } catch (e) {
      // Do something when catch error
      console.log(e)
    }
    var self = this;
    var a = wx.getStorageSync('cookie') || [];
    this.setData({
      cookie: a
    })
    wx.request({
      url: "https://csb2c.fenxiangqu.cn/xcx_classify_1",
      data: {
        a: ""
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Cookie': "LID=" + this.data.cookie
      },
      method: "POST",
      success: (res) => {
        if (res.data.length) {
          self.setData({
            docs: res.data,
            fid: res.data[0].flguid
          })
          self.loadsj(self.data.fid)
        }
        wx.hideToast()
      },
      fail: (res) => {
        console.log(res)
        wx.showToast({
          title: '网络故障啦！',
          icon: 'success',
          duration: 1000
        })
        wx.hideToast()
      }
    })
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },
  figli:function(e){
    var self = this;
    if(e.currentTarget.id){
      this.setData({
        fid: e.currentTarget.id
      })
      self.loadsj(e.currentTarget.id)
    }
  },
  imgError:function(e){
    const self = this;
    const m = e.currentTarget.dataset.m,
        n = e.currentTarget.dataset.n;
    const html = "docsPanren[" + m +"].children["+n+"].imgurl";
    self.setData({
      [html]: self.data.imgerror
    })
  },
  loadsj:function(obj){
    var self = this;
    wx.request({
      url: "https://csb2c.fenxiangqu.cn/xcx_classify_2",
      data: {
        guid: obj
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: "POST",
      success: res => {
        if (res.data) {
          self.setData({
            docsPanren: res.data
          })
        }
      },
      fail: res => {
        wx.showToast({
          title: '网络故障啦！',
          icon: 'success',
          duration: 1000
        })
      }
    })
  },
  commType:e=>{
    wx.navigateTo({
      url: '../comm/comm?guid=' + e.currentTarget.id + '&tier=' + e.currentTarget.dataset.tier +'&px=1'+'&sou=&sy=&page=1'
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})